package com.hmsm.server.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

import rtx.RTXSvrApi;

public class RTXSendNotifyUtil {

	private InetAddress LocalIP = null;
    /**
     *  @Description:取得服务器IP地址   
     *  @MethodName :catchLocalIP
     *  @Author     :fengt
     *  @CreateDate :2013-10-17 下午05:13:58 
     *  @return
     **/
    public InetAddress catchLocalIP(){   
        try{   
             LocalIP = InetAddress.getLocalHost();   
         }catch (UnknownHostException e){   
        	 System.out.println(e.getMessage());
        }   
        return LocalIP;   
    }  
    /**
     * 邮件提醒 测试
     * @param receivers String 接收人(多个接收人以逗号分隔)
     * @param title String 邮件标题
     * @param msg String 邮件内容
     * @param type String 0:普通邮件 1:紧急邮件
     * @param delayTime String 显示停留时间(毫秒) 0:为永久停留(用户关闭时才关闭)
     * @return int 0:操作成功 非0:操作不成功
     */
    public static void sendNotify(String receivers, String title, String msg, String type, String delayTime){
    	//获取服务器IP
    	RTXSendNotifyUtil strIP = new RTXSendNotifyUtil();
    	InetAddress InetIP = strIP.catchLocalIP();
    	String SvrIP = (InetIP.toString()).substring((InetIP.toString()).lastIndexOf("/")+1,(InetIP.toString()).length());
    	//设置端口
    	int iPort = 6000;
    	int iRet= -1;
   
    	RTXSvrApi  RtxsvrapiObj = new RTXSvrApi(); 
    	RtxsvrapiObj.setServerPort(iPort);
    	RtxsvrapiObj.setServerIP(SvrIP);
    	
    	if(RtxsvrapiObj.Init()){   
    		iRet = RtxsvrapiObj.sendNotify(receivers,title,msg,type,delayTime);
    		if (iRet == 0){//返回0表示成功
    			   System.out.println("信息已成功推送至RTX客户端");
    		}else{
    			   System.out.println("信息推送失败");
    		}

    	}
    	RtxsvrapiObj.UnInit();
    }
}
